<?php
namespace app\common\controller;

/**
 * 巡店明细类
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/11/18
 * Time: 17:33
 */
class PatrolRecord{

    /**
     * 获取巡店明细工位信息
     * @param $cp_type
     * @param $cp_branchid
     * @param $cp_floorid
     * @param $branchid
     * @param $floorid
     * @param $regionid
     * @param $wsid
     * @return array
     */
    public function get_pr_ws_info($cp_type,$cp_branchid,$cp_floorid,$branchid,$floorid,$regionid,$wsid){
        $data = [];

        $maps = [];
        $maps[] = ['key','=','cp_ws_cc'];
        $conf_info = model('conf')->get_list($maps);
        $conf_info_new = [];
        foreach ($conf_info as $k => $v) {
            $conf_info_new[$v['key']] = $v['value'];
        }
        $cp_ws_cc_arr = json_decode($conf_info_new['cp_ws_cc'],true);

        $maps = [];
        $maps[] = ['cp_type','=',$cp_type];
        $maps[] = ['cp_branchid','=',$cp_branchid];
        $maps[] = ['cp_floorid','=',$cp_floorid];
        $maps[] = ['branchid','=',$branchid];
        $maps[] = ['floorid','=',$floorid];
        $maps[] = ['regionid','=',$regionid];
        $maps[] = ['wsid','=',$wsid];
        $maps[] = ['status','=',1];
        $crs_detail = model('cp_region_ws')->get_detail($maps,'id,use_status,use_rate,person_num,is_holiday_work,is_evening_work,ccids,remark,status');

        $data['use_status'] = $crs_detail['use_status'];
        $data['use_status_zw'] = $crs_detail->use_status_name;
        $data['use_rate'] = $crs_detail['use_rate'];
        $data['person_num'] = ($crs_detail['use_status'] == 1) ? $crs_detail['person_num'] : 0;
        $data['is_holiday_work'] = $crs_detail['is_holiday_work'];
        $data['is_holiday_work_zw'] = $crs_detail->is_holiday_work_name;
        $data['is_evening_work'] = $crs_detail['is_evening_work'];
        $data['is_evening_work_zw'] = $crs_detail->is_evening_work_name;

        $ccids_arr = json_decode($crs_detail['ccids'],true);
        $ccids_arr_new = [];
        foreach($ccids_arr as $k => $v){
            $ccids_arr_new[] = isset($cp_ws_cc_arr[$v]) ? $cp_ws_cc_arr[$v] : '';
        }

        $data['ccids'] = implode('，',$ccids_arr_new);
        $data['remark'] = $crs_detail['remark'];
        $data['status'] = $crs_detail['status'];
        $data['status_zw'] = $crs_detail->status_name;

        return $data;
    }
}